package bl;

import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

public class IntegersFriendClientData implements FriendClientDataI {

	public final static int BLOCK_SIZE = 16;
	public final static String ENC_ALG = "AES/CBC/NoPadding"; // "AES/CBC/PKCS5Padding";
																// // ;
	public final static int keyLengthBits = 128;

	SecretKey commonSecretKey;
	IntegersClientData clientData;

	public IntegersFriendClientData(SecretKey sc, IntegersClientData clientData) {
		this.commonSecretKey = sc;
		this.clientData = clientData;
	}

	public IntegersFriendClientData(IntegersPublicParameters ipp) {
		this.clientData = new IntegersClientData(ipp);

		// Generate (AES) key:
		KeyGenerator keyGen = null;
		try {
			keyGen = KeyGenerator.getInstance("AES");
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		keyGen.init(keyLengthBits);
		this.commonSecretKey = keyGen.generateKey();
	}

	public IntegersFriendClientData(SecretKey sc,
			BigInteger identityPublicParameter) {
		this.commonSecretKey = sc;
		this.clientData = new IntegersClientData(identityPublicParameter);
	}

	public IntegersFriendClientData(SecretKey sc,
			BigInteger identityPublicParameter,
			BigInteger identitySecretParameter) {
		this.commonSecretKey = sc;
		this.clientData = new IntegersClientData(identityPublicParameter,
				identitySecretParameter);
	}

	@Override
	public Object getCommonSecretKey() {
		return this.commonSecretKey;
	}

	@Override
	public Object getIdentityPublicParameter() {
		return this.clientData.getIdentityPublicParameter();
	}

	@Override
	public Object getIdentitySecretParameter() {
		return this.clientData.getIdentitySecretParameter();
	}

	@Override
	public ClientDataI getClientData() {
		return this.clientData;
	}
}
